import java.util.Stack;

/*
 * 1. operates on any primitive function
 * 2. sends any name as an object on the run stack 
 */

public class RuleApplyY {
	
	Stack<ControlElement> control ;
	Stack<String> stack ;
	Environment environment;
	
	public RuleApplyY(Stack<ControlElement> control, Stack<String> stack, Environment environment){
		this.control = control;
		this.stack = stack;
		this.environment = environment;
	}
	
	/*
	 * Just replace lambda with eta:3:x:#
	 * 1. pop gamma
	 * 2. pop Y from stack
	 * 3. pop lambda and push eta
	 */
	void applyRule() {
		assert(control.peek().content.equals("gamma")):"applyY: gamma expected";
		assert(stack.peek().equals("Y")):"applyY: Y expected on stack";
		control.pop();
		stack.pop();
		String lambda = stack.pop();
		stack.push(lambda.replace("lambda", "eta"));
	}

	boolean checkRule() {
		String controlTop = control.peek().content;
		if (controlTop.equals("gamma") && stack.peek().equals("Y")) {
			return true;
		} else {
			return false;
		}
	}

}
